-- Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
--
-- this file licensed under the Mulan PSL v2.
-- You can use this software according to the terms and conditions of the Mulan PSL v2.
-- You may obtain a copy of Mulan PSL v2 at: http://license.coscl.org.cn/MulanPSL2
--
-- THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
-- PURPOSE.
-- See the Mulan PSL v2 for more details.
--
-- Author: auto generate
-- Create: 2025-5-7
-- Description: DO NOT EDIT; Code generated by "model.lua.mako"
local mdb = require 'mc.mdb'
local class = require 'mc.class_mgnt'
local privilege = require 'mc.privilege'

local active_standby_local_class_types = require 'class.types.ActiveStandbyLocal'
local active_standby_remote_class_types = require 'class.types.ActiveStandbyRemote'
local active_standby_service_class_types = require 'class.types.ActiveStandbyService'
local local_intf_types = require 'active_standby_mgmt.json_types.Local'
local status_intf_types = require 'active_standby_mgmt.json_types.Status'
local properties_intf_types = require 'active_standby_mgmt.json_types.Properties'
local remote_intf_types = require 'active_standby_mgmt.json_types.Remote'
local switch_rule_intf_types = require 'active_standby_mgmt.json_types.SwitchRule'

local ActiveStandbyLocal = {
    ['prop_configs'] = {
        ['Address'] = {
            ['usage'] = {'CSR'},
            ['baseType'] = 'String',
            ['default'] = '',
            ['validator'] = active_standby_local_class_types.Address
        },
        ['Port'] = {
            ['usage'] = {'CSR'},
            ['baseType'] = 'U16',
            ['default'] = 51000,
            ['validator'] = active_standby_local_class_types.Port
        },
        ['Presence'] = {
            ['usage'] = {'CSR'},
            ['baseType'] = 'U8',
            ['default'] = 1,
            ['validator'] = active_standby_local_class_types.Presence
        }
    },
    ['default_props'] = {['Address'] = '', ['Port'] = 51000, ['Presence'] = 1},
    ['mdb_prop_configs'] = {
        ['bmc.kepler.Managers.ActiveStandby.Local'] = {
            ['Id'] = {
                ['baseType'] = 'U8',
                ['readOnly'] = true,
                ['default'] = 0,
                ['options'] = {['emitsChangedSignal'] = 'false'},
                ['usage'] = {'CSR'},
                ['validator'] = local_intf_types.Id
            },
            ['ActiveAllowed'] = {
                ['baseType'] = 'Boolean',
                ['readOnly'] = true,
                ['default'] = false,
                ['options'] = {['emitsChangedSignal'] = 'false'},
                ['validator'] = local_intf_types.ActiveAllowed
            },
            ['StandbyAllowed'] = {
                ['baseType'] = 'Boolean',
                ['readOnly'] = true,
                ['default'] = false,
                ['options'] = {['emitsChangedSignal'] = 'false'},
                ['validator'] = local_intf_types.StandbyAllowed
            }
        },
        ['bmc.kepler.Managers.ActiveStandby.Status'] = {
            ['ActiveStatus'] = {
                ['baseType'] = 'U8',
                ['readOnly'] = true,
                ['options'] = {['emitsChangedSignal'] = 'true'},
                ['validator'] = status_intf_types.ActiveStatus
            },
            ['CommunicationStatus'] = {
                ['baseType'] = 'U8',
                ['readOnly'] = true,
                ['default'] = 1,
                ['options'] = {['emitsChangedSignal'] = 'true'},
                ['validator'] = status_intf_types.CommunicationStatus
            }
        },
        ['bmc.kepler.Object.Properties'] = {
            ['ClassName'] = {
                ['baseType'] = 'String',
                ['readOnly'] = true,
                ['validator'] = properties_intf_types.ClassName
            },
            ['ObjectName'] = {
                ['baseType'] = 'String',
                ['readOnly'] = true,
                ['validator'] = properties_intf_types.ObjectName
            },
            ['ObjectIdentifier'] = {
                ['baseType'] = 'Struct',
                ['$ref'] = '#/defs/StructIdentifier',
                ['readOnly'] = true,
                ['validator'] = properties_intf_types.ObjectIdentifier
            }
        }
    },
    ['mdb_method_configs'] = {
        ['bmc.kepler.Managers.ActiveStandby.Local'] = {
            ['SwitchStatus'] = {['req'] = {{['baseType'] = 'U8', ['param'] = 'Status'}}, ['rsp'] = {}}
        }
    },
    ['mdb_classes'] = mdb.get_class_obj('/bmc/kepler/Managers/:ManagerId/ActiveStandby/Local'),
    ['new_mdb_objects'] = mdb.new_objects_builder({
        ['bmc.kepler.Managers.ActiveStandby.Local'] = {
            ['property_defaults'] = {['Id'] = 0, ['ActiveAllowed'] = false, ['StandbyAllowed'] = false},
            ['interface_types'] = local_intf_types
        },
        ['bmc.kepler.Managers.ActiveStandby.Status'] = {
            ['property_defaults'] = {
                ['ActiveStatus'] = status_intf_types.ActiveStatus.default[1],
                ['CommunicationStatus'] = 1
            },
            ['interface_types'] = status_intf_types
        },
        ['bmc.kepler.Object.Properties'] = {
            ['property_defaults'] = {
                ['ClassName'] = properties_intf_types.ClassName.default[1],
                ['ObjectName'] = properties_intf_types.ObjectName.default[1],
                ['ObjectIdentifier'] = properties_intf_types.ObjectIdentifier.default[1]
            },
            ['interface_types'] = properties_intf_types
        }
    })
}

local ActiveStandbyRemote = {
    ['prop_configs'] = {
        ['Address'] = {
            ['usage'] = {'CSR'},
            ['baseType'] = 'String',
            ['default'] = '',
            ['validator'] = active_standby_remote_class_types.Address
        },
        ['Port'] = {
            ['usage'] = {'CSR'},
            ['baseType'] = 'U16',
            ['default'] = 51000,
            ['validator'] = active_standby_remote_class_types.Port
        },
        ['Presence'] = {
            ['usage'] = {'CSR'},
            ['baseType'] = 'U8',
            ['default'] = 1,
            ['validator'] = active_standby_remote_class_types.Presence
        }
    },
    ['default_props'] = {['Address'] = '', ['Port'] = 51000, ['Presence'] = 1},
    ['mdb_prop_configs'] = {
        ['bmc.kepler.Managers.ActiveStandby.Remote'] = {
            ['Id'] = {
                ['baseType'] = 'U8',
                ['readOnly'] = true,
                ['default'] = 0,
                ['options'] = {['emitsChangedSignal'] = 'false'},
                ['usage'] = {'CSR'},
                ['validator'] = remote_intf_types.Id
            }
        },
        ['bmc.kepler.Managers.ActiveStandby.Status'] = {
            ['ActiveStatus'] = {
                ['baseType'] = 'U8',
                ['readOnly'] = true,
                ['options'] = {['emitsChangedSignal'] = 'true'},
                ['validator'] = status_intf_types.ActiveStatus
            },
            ['CommunicationStatus'] = {
                ['baseType'] = 'U8',
                ['readOnly'] = true,
                ['default'] = 1,
                ['options'] = {['emitsChangedSignal'] = 'true'},
                ['validator'] = status_intf_types.CommunicationStatus
            }
        },
        ['bmc.kepler.Object.Properties'] = {
            ['ClassName'] = {
                ['baseType'] = 'String',
                ['readOnly'] = true,
                ['validator'] = properties_intf_types.ClassName
            },
            ['ObjectName'] = {
                ['baseType'] = 'String',
                ['readOnly'] = true,
                ['validator'] = properties_intf_types.ObjectName
            },
            ['ObjectIdentifier'] = {
                ['baseType'] = 'Struct',
                ['$ref'] = '#/defs/StructIdentifier',
                ['readOnly'] = true,
                ['validator'] = properties_intf_types.ObjectIdentifier
            }
        }
    },
    ['mdb_classes'] = mdb.get_class_obj('/bmc/kepler/Managers/:ManagerId/ActiveStandby/Remotes/:Id'),
    ['new_mdb_objects'] = mdb.new_objects_builder({
        ['bmc.kepler.Managers.ActiveStandby.Remote'] = {
            ['property_defaults'] = {['Id'] = 0},
            ['interface_types'] = remote_intf_types
        },
        ['bmc.kepler.Managers.ActiveStandby.Status'] = {
            ['property_defaults'] = {
                ['ActiveStatus'] = status_intf_types.ActiveStatus.default[1],
                ['CommunicationStatus'] = 1
            },
            ['interface_types'] = status_intf_types
        },
        ['bmc.kepler.Object.Properties'] = {
            ['property_defaults'] = {
                ['ClassName'] = properties_intf_types.ClassName.default[1],
                ['ObjectName'] = properties_intf_types.ObjectName.default[1],
                ['ObjectIdentifier'] = properties_intf_types.ObjectIdentifier.default[1]
            },
            ['interface_types'] = properties_intf_types
        }
    })
}

local SwitchRule = {
    ['mdb_prop_configs'] = {
        ['bmc.kepler.Managers.ActiveStandby.SwitchRule'] = {
            ['RuleType'] = {
                ['baseType'] = 'U8',
                ['readOnly'] = true,
                ['default'] = 0,
                ['options'] = {['emitsChangedSignal'] = 'false'},
                ['usage'] = {'CSR'},
                ['validator'] = switch_rule_intf_types.RuleType
            },
            ['Threshold'] = {
                ['baseType'] = 'U32',
                ['readOnly'] = true,
                ['default'] = 1,
                ['options'] = {['emitsChangedSignal'] = 'false'},
                ['usage'] = {'CSR'},
                ['validator'] = switch_rule_intf_types.Threshold
            },
            ['Reading'] = {
                ['baseType'] = 'U32',
                ['readOnly'] = false,
                ['default'] = 0,
                ['options'] = {['emitsChangedSignal'] = 'false'},
                ['usage'] = {'CSR'},
                ['privilege'] = {['read'] = {'ReadOnly'}, ['write'] = {'ReadOnly'}},
                ['validator'] = switch_rule_intf_types.Reading
            },
            ['Enabled'] = {
                ['baseType'] = 'Boolean',
                ['readOnly'] = false,
                ['default'] = true,
                ['options'] = {['emitsChangedSignal'] = 'false'},
                ['usage'] = {'CSR'},
                ['privilege'] = {['read'] = {'ReadOnly'}, ['write'] = {'BasicSetting'}},
                ['validator'] = switch_rule_intf_types.Enabled
            },
            ['Operator'] = {
                ['baseType'] = 'U8',
                ['readOnly'] = true,
                ['default'] = 5,
                ['options'] = {['emitsChangedSignal'] = 'false'},
                ['usage'] = {'CSR'},
                ['validator'] = switch_rule_intf_types.Operator
            },
            ['Direction'] = {
                ['baseType'] = 'U8',
                ['readOnly'] = true,
                ['default'] = 0,
                ['options'] = {['emitsChangedSignal'] = 'false'},
                ['usage'] = {'CSR'},
                ['validator'] = switch_rule_intf_types.Direction
            },
            ['Description'] = {
                ['baseType'] = 'String',
                ['readOnly'] = true,
                ['default'] = '',
                ['options'] = {['emitsChangedSignal'] = 'false'},
                ['usage'] = {'CSR'},
                ['validator'] = switch_rule_intf_types.Description
            }
        },
        ['bmc.kepler.Object.Properties'] = {
            ['ClassName'] = {
                ['baseType'] = 'String',
                ['readOnly'] = true,
                ['validator'] = properties_intf_types.ClassName
            },
            ['ObjectName'] = {
                ['baseType'] = 'String',
                ['readOnly'] = true,
                ['validator'] = properties_intf_types.ObjectName
            },
            ['ObjectIdentifier'] = {
                ['baseType'] = 'Struct',
                ['$ref'] = '#/defs/StructIdentifier',
                ['readOnly'] = true,
                ['validator'] = properties_intf_types.ObjectIdentifier
            }
        }
    },
    ['mdb_classes'] = mdb.get_class_obj('/bmc/kepler/Managers/:ManagerId/ActiveStandby/SwitchRules/:Id'),
    ['new_mdb_objects'] = mdb.new_objects_builder({
        ['bmc.kepler.Managers.ActiveStandby.SwitchRule'] = {
            ['property_defaults'] = {
                ['RuleType'] = 0,
                ['Threshold'] = 1,
                ['Reading'] = 0,
                ['Enabled'] = true,
                ['Operator'] = 5,
                ['Direction'] = 0,
                ['Description'] = ''
            },
            ['privileges'] = {
                ['props'] = {
                    ['Reading'] = {['read'] = privilege.ReadOnly, ['write'] = privilege.ReadOnly},
                    ['Enabled'] = {['read'] = privilege.ReadOnly, ['write'] = privilege.BasicSetting}
                }
            },
            ['interface_types'] = switch_rule_intf_types
        },
        ['bmc.kepler.Object.Properties'] = {
            ['property_defaults'] = {
                ['ClassName'] = properties_intf_types.ClassName.default[1],
                ['ObjectName'] = properties_intf_types.ObjectName.default[1],
                ['ObjectIdentifier'] = properties_intf_types.ObjectIdentifier.default[1]
            },
            ['interface_types'] = properties_intf_types
        }
    })
}

local ActiveStandbyService = {
    ['prop_configs'] = {
        ['DefaultActiveId'] = {
            ['usage'] = {'CSR'},
            ['baseType'] = 'U8',
            ['default'] = 1,
            ['validator'] = active_standby_service_class_types.DefaultActiveId
        },
        ['StandbyToActiveWrite'] = {
            ['usage'] = {'CSR'},
            ['baseType'] = 'U8',
            ['validator'] = active_standby_service_class_types.StandbyToActiveWrite
        },
        ['ActiveToStandbyWrite'] = {
            ['usage'] = {'CSR'},
            ['baseType'] = 'U8',
            ['validator'] = active_standby_service_class_types.ActiveToStandbyWrite
        },
        ['StandbyToActiveWriteProtect'] = {
            ['usage'] = {'CSR'},
            ['baseType'] = 'U8',
            ['validator'] = active_standby_service_class_types.StandbyToActiveWriteProtect
        },
        ['ActiveToStandbyWriteProtect'] = {
            ['usage'] = {'CSR'},
            ['baseType'] = 'U8',
            ['validator'] = active_standby_service_class_types.ActiveToStandbyWriteProtect
        },
        ['HeartbeatWrite'] = {
            ['usage'] = {'CSR'},
            ['baseType'] = 'U8',
            ['validator'] = active_standby_service_class_types.HeartbeatWrite
        },
        ['HealthStatus'] = {
            ['usage'] = {'CSR'},
            ['baseType'] = 'U8',
            ['validator'] = active_standby_service_class_types.HealthStatus
        },
        ['ActiveRead'] = {
            ['usage'] = {'CSR'},
            ['baseType'] = 'U8',
            ['validator'] = active_standby_service_class_types.ActiveRead
        },
        ['BoardFullySeated'] = {
            ['usage'] = {'CSR'},
            ['baseType'] = 'U8',
            ['validator'] = active_standby_service_class_types.BoardFullySeated
        },
        ['HeartbeatIntervalMS'] = {
            ['usage'] = {'CSR'},
            ['baseType'] = 'U32',
            ['default'] = 300,
            ['validator'] = active_standby_service_class_types.HeartbeatIntervalMS
        },
        ['HeartbeatTimeoutMS'] = {
            ['usage'] = {'CSR'},
            ['baseType'] = 'U32',
            ['default'] = 3000,
            ['validator'] = active_standby_service_class_types.HeartbeatTimeoutMS
        },
        ['ActiveMonitorIntervalMS'] = {
            ['usage'] = {'CSR'},
            ['baseType'] = 'U32',
            ['validator'] = active_standby_service_class_types.ActiveMonitorIntervalMS
        }
    },
    ['default_props'] = {
        ['DefaultActiveId'] = 1,
        ['StandbyToActiveWrite'] = active_standby_service_class_types.StandbyToActiveWrite.default[1],
        ['ActiveToStandbyWrite'] = active_standby_service_class_types.ActiveToStandbyWrite.default[1],
        ['StandbyToActiveWriteProtect'] = active_standby_service_class_types.StandbyToActiveWriteProtect.default[1],
        ['ActiveToStandbyWriteProtect'] = active_standby_service_class_types.ActiveToStandbyWriteProtect.default[1],
        ['HeartbeatWrite'] = active_standby_service_class_types.HeartbeatWrite.default[1],
        ['HealthStatus'] = active_standby_service_class_types.HealthStatus.default[1],
        ['ActiveRead'] = active_standby_service_class_types.ActiveRead.default[1],
        ['BoardFullySeated'] = active_standby_service_class_types.BoardFullySeated.default[1],
        ['HeartbeatIntervalMS'] = 300,
        ['HeartbeatTimeoutMS'] = 3000,
        ['ActiveMonitorIntervalMS'] = active_standby_service_class_types.ActiveMonitorIntervalMS.default[1]
    }
}

local M = {}

function M.init(bus)
    class('ActiveStandbyLocal', ActiveStandbyLocal):set_bus(bus)
    class('ActiveStandbyRemote', ActiveStandbyRemote):set_bus(bus)
    class('SwitchRule', SwitchRule):set_bus(bus)
    class('ActiveStandbyService', ActiveStandbyService):set_bus(bus)
end

-- The callback needs to be registered during app initialization
function M.ImplActiveStandbyLocalLocalSwitchStatus(cb)
    class('ActiveStandbyLocal')['bmc.kepler.Managers.ActiveStandby.Local'].SwitchStatus = function(obj, ctx, ...)
        local req = local_intf_types.SwitchStatusReq.new(...):validate(nil, nil, true)
        local rsp = local_intf_types.SwitchStatusRsp.new(cb(obj, ctx, req:unpack())):validate()
        return rsp:unpack(true)
    end
end

return M
